package com.openbravo.pos.panels;

import java.util.List;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import com.openbravo.bean.Customer;
import com.openbravo.bean.CustomerCategory;
import com.openbravo.data.basic.BasicException;
import cn.ekuma.data.ui.swing.dnd.AbstractJBeanDropPanel;
import com.openbravo.pos.base.AppLocal;
import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.epos.db.table.I_Customer;


public class JDropCustomerByCategoryPanel extends JPanel {
	I_DataLogic dlSales ;
	/**
	 * Create the panel.
	 */
	public JDropCustomerByCategoryPanel(final I_DataLogic dlSales2) {
		initComponents();
		this.dlSales=dlSales2;
		add(new AbstractJBeanDropPanel<CustomerCategory,Customer>(){
			@Override
			public void doDropInsert(List<Customer> beans) {
					try {
						for(Customer p:beans){			
							dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, bean.getID());
							p.setCategoryid(bean.getID());
						  }
						} catch (BasicException e) {
							e.printStackTrace();
						}
			}

			@Override
			public String readerBean(CustomerCategory obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("Menu.CustomerCategories");
			}

			@Override
			public void doDropDelete(List<Customer> dropList) {
				try {
					for(Customer p:dropList){			
						dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, null);
						p.setCategoryid(null);
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
				
			}
		});
		add(new AbstractJBeanDropPanel<CustomerCategory,Customer>(){
			@Override
			public void doDropInsert(List<Customer> beans) {
					try {
						for(Customer p:beans){			
							dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, bean.getID());
							p.setCategoryid(bean.getID());
						  }
						} catch (BasicException e) {
							e.printStackTrace();
						}
			}

			@Override
			public void doDropDelete(List<Customer> dropList) {
				try {
					for(Customer p:dropList){			
						dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, null);
						p.setCategoryid(null);
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
				
			}
			
			@Override
			public String readerBean(CustomerCategory obj) {
				return obj.getName();
			}

			
			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("Menu.CustomerCategories");
			}
		});
		add(new AbstractJBeanDropPanel<CustomerCategory,Customer>(){
			@Override
			public void doDropInsert(List<Customer> beans) {
					try {
						for(Customer p:beans){			
							dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, bean.getID());
							p.setCategoryid(bean.getID());
						  }
						} catch (BasicException e) {
							e.printStackTrace();
						}
			}
			@Override
			public void doDropDelete(List<Customer> dropList) {
				try {
					for(Customer p:dropList){			
						dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, null);
						p.setCategoryid(null);
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
				
			}

			@Override
			public String readerBean(CustomerCategory obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("Menu.CustomerCategories");
			}
		});
		add(new AbstractJBeanDropPanel<CustomerCategory,Customer>(){
			@Override
			public void doDropInsert(List<Customer> beans) {
					try {
						for(Customer p:beans){			
							dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, bean.getID());
							p.setCategoryid(bean.getID());
						  }
						} catch (BasicException e) {
							e.printStackTrace();
						}
			}

			@Override
			public void doDropDelete(List<Customer> dropList) {
				try {
					for(Customer p:dropList){			
						dlSales2.updateByFieldWithIKeyed(p, I_Customer.CATEGORY, null);
						p.setCategoryid(null);
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
				
			}
			
			@Override
			public String readerBean(CustomerCategory obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("Menu.CustomerCategories");
			}
		});
		
	}
	private void initComponents() {
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
	}
	
	public static String getTabName(){
		return AppLocal.getIntString("Menu.CustomerCategories");
	}
}